//
//  HDVerfiyTools.m
//  HDFrameWork
//
//  Created by yscompany on 2018/11/12.
//  Copyright © 2018 yscompany. All rights reserved.
//

#import "HDVerfiyTools.h"

@implementation HDVerfiyTools
// 字符串非空判断
+ (NSString *)getSafeString:(NSString *)inputStr {
    if ([inputStr isKindOfClass:[NSString class]]) {
        if (inputStr.length > 0) {
            return inputStr;
        }
    }
    return @"";
}
// 获取自定义格式的当前日期字符串转换数据
+ (NSString *)getCurrentDateStrFormatterStr:(NSString *)formatteStr {
    NSString *dateStr = @"";
    NSDate * date = [NSDate date];
    NSDateFormatter *formatter = [NSDateFormatter new];
    [formatter setDateFormat:formatteStr];
    dateStr = [formatter stringFromDate:date];
    return dateStr;
}
// 是否手机号
+ (BOOL)isPhoneNumberStr:(NSString *)phoneNumStr {
    NSString * regularExpression = @"^[0-9]{11}";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regularExpression];
    return [phoneTest evaluateWithObject:phoneNumStr];
}
// 是否香港手机号
+ (BOOL)isHongKongMobile:(NSString *)content
{
    NSString * regularExpression = @"^[0-9]{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regularExpression];
    return [phoneTest evaluateWithObject:content];
}
// 是否邮箱地址
+ (BOOL)isEmail:(NSString *)content
{
    NSString *strPattern = @"\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",strPattern];
    return [phoneTest evaluateWithObject:content];
}
// 6-20 位 密码校验 数字特殊字符以及英文混合
+ (BOOL)isRegistPWD:(NSString *)string
{
    NSString *strPattern = @"^(?=[a-zA-Z0-9]*(?:[a-zA-Z][0-9]|[0-9][a-zA-Z]))[a-zA-Z0-9]{6,20}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",strPattern];
    return [phoneTest evaluateWithObject:string];
}
//校验身份证的长度和类型
+ (BOOL)isCertifierCardNo:(NSString *)cardNo
{
    NSString *checkExpressions = @"^[1-9]([0-9]{14}|[0-9]{17}|[0-9]{16}[Xx])$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",checkExpressions];
    return [phoneTest evaluateWithObject:cardNo];
}
// 转换 手机号 前三后四展示
+(NSString *)switchHiddenPhoneNo:(NSString *)phoneNoStr {
    if ([HDVerfiyTools getSafeString:phoneNoStr].length > 7) {
        phoneNoStr = [NSString stringWithFormat:@"%@****%@",[phoneNoStr substringWithRange:NSMakeRange(0, 2)],[phoneNoStr substringWithRange:NSMakeRange(5, 7)]];
    }
    return phoneNoStr;
}
// 转换 身份证号码 前三后四展示
+ (NSString *)switchHiddenBanckCardNo:(NSString *)bankCardNoStr {
    if ([HDVerfiyTools getSafeString:bankCardNoStr].length > 7) {
        bankCardNoStr = [NSString stringWithFormat:@"%@************%@",[bankCardNoStr substringWithRange:NSMakeRange(0, 2)],[bankCardNoStr substringWithRange:NSMakeRange(5, 7)]];
    }
    return bankCardNoStr;
}
@end
